

#include "atomic_op_namespace.h"

#include <sys/atomic.h>

uint32_t
atomic_swap_32(volatile uint32_t *addr, uint32_t new)
{
	uint32_t old;

	do {
		old = *addr;
	} while (atomic_cas_32(addr, old, new) != old);

	return (old);
}

crt_alias(__atomic_exchange_4,_atomic_swap_32)

#undef atomic_swap_32
atomic_op_alias(atomic_swap_32,_atomic_swap_32)
#undef atomic_swap_uint
atomic_op_alias(atomic_swap_uint,_atomic_swap_32)
__strong_alias(_atomic_swap_uint,_atomic_swap_32)
crt_alias(__sync_lock_test_and_set_4,_atomic_swap_32)
#if !defined(_LP64)
#undef atomic_swap_ulong
atomic_op_alias(atomic_swap_ulong,_atomic_swap_32)
__strong_alias(_atomic_swap_ulong,_atomic_swap_32)
#undef atomic_swap_ptr
atomic_op_alias(atomic_swap_ptr,_atomic_swap_32)
__strong_alias(_atomic_swap_ptr,_atomic_swap_32)
#endif /* _LP64 */
